# -*- coding: utf-8 -*-

import time
import DBLink.dbHelp


dbHelp = DBLink.dbHelp


import Encapsulation.Complete


complete = Encapsulation.Complete


def _api_test_question_add(_request):
    '''
       /api/test.question.add

       功能：题库--题目新增     负责人：陈公智
       编写：cgz
       :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},
       "ansertTab":[{"AnswerText": "", "OrderCode": "A"},{"AnswerText": "", "OrderCode": "B"},{"AnswerText": "", "OrderCode": "C"},{"AnswerText": "", "OrderCode": "D"}],
       "operationUserID":2, "ItemType":"","ItemQuestion":"", "ItemAnswer":"", "DepartmentID":2, "JobID":3, "HowHard":"", "GroupType":""}
       :param _request["ansertTab"]:传入字典（答案字典）
                        :param _request["AnswerText"]:答案内容
                        :param _request["OrderCode"]:答案序号
       :param _request["operationUserID"]:操作人
        :param _request["ItemType"]:试题类型
        :param _request["ItemQuestion"]:题目
        :param _request["ItemAnswer"]:参考答案
        :param _request["DepartmentID"]:部门ID
        :param _request["JobID"]:JobID
        :param _request["HowHard"]:标签-难易度
        :param _request["GroupType"]:标签-知识点
       :return:_request返回信息={"ErrorInfo": {"ErrorCode":, "ErrorMsg": ""}, "IsError": false, "ReturnValue": true}

       '''
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    if _request!="JSON解析失败":
        if 'JobID' in _request:
            strSelSql = """
                SELECT
                COUNT(*) AS NUM
                FROM
                tb_class T1
                WHERE
                T1.PID='""" + str(_request["JobID"]) + """'
                AND
                IsDelete='0'
            """

            returnSel = dbHelp.Select(strSelSql)
            if returnSel["Value"][0]["NUM"] == 0:
                # 获取试题最新ID
                objIdReturn = dbHelp.GetNewids("itema")

                ItemAnswer = str(_request["ItemAnswer"])

                if str(_request["ItemType"]) == "单选" \
                        or str(_request["ItemType"]) == "多选" \
                        or str(_request["ItemType"]) == "判断":
                    ItemAnswer = ItemAnswer.upper()
                insertSql = """
                    insert into itema
                        (
                        create_user,
                        create_time,
                        ItemCode,
                        ItemType,
                        ItemQuestion,
                        ItemAnswer,
                        HowHard,
                        GroupType,
                        DepartmentID,
                        JobID,
                        IsDelete
                        )
                        VALUES
                        (
                        '""" + str(_request["operationUserID"]) + """',
                        DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'),
                        '""" + str(objIdReturn["Value"]) + """',
                        '""" + str(_request["ItemType"]) + """',
                        '""" + str(_request["ItemQuestion"]) + """',
                        '""" + str(ItemAnswer) + """',

                        '""" + str(_request["HowHard"]) + """',
                        '""" + str(_request["GroupType"]) + """',

                        '""" + str(_request["DepartmentID"]) + """',
                        '""" + str(_request["JobID"]) + """',
                        '0'
                        )
                """

                ReturnObject = dbHelp.Exec(insertSql)
                _respon["IsError"] = ReturnObject["IsError"]
                _respon["ErrorInfo"]["ErrorCode"] = ReturnObject["ErrorCode"]
                _respon["ErrorInfo"]["ErrorMsg"] = ReturnObject["ErrorMsg"]
                _respon["ReturnValue"] = ReturnObject["ReturnValue"]
                if ReturnObject["ReturnValue"] != False:
                    # 判断试题类型，选择题，判断题需要添加从表信息
                    if str(_request["ItemType"]) == "单选" \
                            or str(_request["ItemType"]) == "多选" \
                            or str(_request["ItemType"]) == "判断":

                        ansertTab = _request["ansertTab"]  # 获取选择的答案

                        cs_int_Number_IDsNeed = len(ansertTab)  # 获取要插入多少条答案

                        objReturn_NewIDs = dbHelp.GetSomeIDs("itemb", cs_int_Number_IDsNeed)  # 新增的ID的列表

                        cx_forlist = range(0, cs_int_Number_IDsNeed)  # 循环用的I的数值列表

                        strSqlSome = ""  # 用于提交的SQL语句集合

                        OrderCode = []
                        AnswerText = []
                        for b in ansertTab:
                            OrderCode.append(b["OrderCode"])
                            AnswerText.append(b["AnswerText"])

                        for i in cx_forlist:
                            insertItemB = """
                                INSERT INTO itemb
                                (
                                create_user,
                                create_time,
                                AnswerCode,
                                ItemCode,
                                OrderCode,
                                AnswerText,
                                IsDelete
                                )
                                VALUES
                                (
                                '""" + str(_request["operationUserID"]) + """',
                                DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'),
                                '""" + str(objReturn_NewIDs["numberList"][i]) + """',
                                '""" + objIdReturn["Value"] + """',
                                 '""" + OrderCode[i] + """',
                                 '""" + AnswerText[i] + """',
                                0
                                )
                            """
                            strSqlSome = strSqlSome + insertItemB + ";"
                        insertObj = dbHelp.Exec(strSqlSome)
                        _respon["IsError"] = insertObj["IsError"]
                        _respon["ErrorInfo"]["ErrorCode"] = insertObj["ErrorCode"]
                        _respon["ErrorInfo"]["ErrorMsg"] = insertObj["ErrorMsg"]
                        _respon["ReturnValue"] = insertObj["ReturnValue"]
                    else:
                        pass
            else:
                _respon["IsError"] = True
                _respon["ErrorInfo"]["ErrorCode"] = 1
                _respon["ErrorInfo"]["ErrorMsg"] = "你选择的不是岗位，请选择岗位后添加"
                _respon["ReturnValue"] = False
        else:
            _respon["IsError"] = True
            _respon["ErrorInfo"]["ErrorCode"] = 1
            _respon["ErrorInfo"]["ErrorMsg"] = "请选择部门岗位！"
            _respon["ReturnValue"] = False

    else:
        _respon["IsError"] = True
        _respon["ErrorInfo"]["ErrorCode"] = 1
        _respon["ErrorInfo"]["ErrorMsg"] = "JSON解析失败"
        _respon["ReturnValue"] = False
    return _respon


def _api_test_question_view_one(_request):
    '''
          /api/test.question.view.one

           功能：题库--题目查询--单记录     负责人：陈公智
           编写：cgz
           :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},"ItemCode":11}
           :param _request["ItemCode"]:题目编码
           :return:_request返回信息={"GroupType": "后端", "ansertList": "[{"AnswerCode"":"1","AnswerText": "", "OrderCode": "A"}, {"AnswerCode"":"2","AnswerText": "", "OrderCode": "B"}, {"AnswerCode"":"3","AnswerText": "", "OrderCode": "C"},
                            {"AnswerCode":"4","AnswerText": "", "OrderCode": "D"}]", "HowHard": "简单", "ItemCode": 11, "ItemQuestion": "选择题啦",
           "ReturnValue": true, "ItemAnswer": "ACD", "ErrorInfo": {"ErrorCode": 0, "ErrorMsg": ""}, "IsError": false}
            :param _request["ansertList"]:返回答案字典(类似于主观题，操作题不存在答案列表： _request["ansertList"]=[])
                        :param _request["AnswerCode"]:答案编码
                        :param _request["AnswerText"]:答案内容
                        :param _request["OrderCode"]:答案序号
            :param _request["GroupType"]:标签-知识点
            :param _request["HowHard"]:标签-难易度
            :param _request["ItemCode"]:题目编码
            :param _request["ItemQuestion"]:题目
            :param _request["ItemAnswer"]:参考答案
            :param _request["ItemType"]:题目类型
           '''
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}

    # 根据ID查询题目主表信息
    selectSql = """
        SELECT
            T1.ItemCode,
            T1.ItemType,
            T1.ItemQuestion,
            T1.HowHard,
            T1.GroupType,
            T1.ItemAnswer
            FROM
            itema T1
            WHERE
            T1.ItemCode= '""" + str(_request["ItemCode"]) + """'
            AND
            T1.IsDelete=0
    """
    returnItem = dbHelp.Select(selectSql)
    _respon["IsError"] = returnItem["IsError"]
    _respon["ErrorInfo"]["ErrorCode"] = returnItem["ErrorCode"]
    _respon["ErrorInfo"]["ErrorMsg"] = returnItem["ErrorMsg"]
    _respon["ReturnValue"] = returnItem["ReturnValue"]

    _respon["ItemCode"] = returnItem["Value"][0]["ItemCode"]
    _respon["ItemType"] = returnItem["Value"][0]["ItemType"]
    _respon["ItemQuestion"] = returnItem["Value"][0]["ItemQuestion"]

    _respon["HowHard"] = returnItem["Value"][0]["HowHard"]
    _respon["GroupType"] = returnItem["Value"][0]["GroupType"]
    _respon["ItemAnswer"] = returnItem["Value"][0]["ItemAnswer"]

    # print selectSql
    # print returnItem["Value"][0]["HowHard"]

    if returnItem["ReturnValue"] != True:
        pass
    else:
        # 查询从表的答案信息
        selSqlItemb = """
            SELECT
            T1.AnswerCode,
            T1.AnswerText,
             T1.OrderCode
            FROM
            itemb T1
            WHERE
            T1.ItemCode= '""" + str(_request["ItemCode"]) + """'
            AND
            T1.IsDelete='0'
        """
        returnItemB = dbHelp.Select(selSqlItemb)
        if returnItemB["Value"] == "":
            _respon["ansertList"] = []
        else:
            _respon["ansertList"] = returnItemB["Value"]
    return _respon


def _api_test_question_del(_request):
    '''
         /api/test.question.del

          功能：题库--试题--删除    负责人：陈公智
          编写：cgz
          :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},"ItemCode":20,"operationUserID":2}
          :param _request["ItemCode"]:题目编码
          :param _request["operationUserID"]:操作者ID
          :return:_request返回信息={"ErrorInfo": {"ErrorCode": 0, "ErrorMsg": ""}, "IsError": false, "ReturnValue": true}
          '''

    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}  # 删除主表信息
    sqlDel = """
            UPDATE itema T1
            SET
            update_user='""" + str(_request["operationUserID"]) + """',
            update_time=DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'),
            T1.IsDelete='1'
            WHERE
            T1.ItemCode='""" + str(_request["ItemCode"]) + """'
        """
    ReturnObject = dbHelp.Exec(sqlDel)
    if ReturnObject["ReturnValue"] != True:
        _respon["IsError"] = ReturnObject["IsError"]
        _respon["ErrorInfo"]["ErrorCode"] = ReturnObject["ErrorCode"]
        _respon["ErrorInfo"]["ErrorMsg"] = "删除失败！"
        _respon["ReturnValue"] = ReturnObject["ReturnValue"]
    else:
        # 主表删除成功后，删除从表信息

        # 判断是否为选择题，判断题，是：删除从表信息
        selTaype = """
            SELECT
            T1.ItemType
            FROM
            itema T1
            WHERE
            T1.ItemCode='""" + str(_request["ItemCode"]) + """'
        """
        ReturnSel = dbHelp.Select(selTaype)
        if str(ReturnSel["Value"][0]["ItemType"]) == "单选" \
                or ReturnSel["Value"][0]["ItemType"] == "多选" \
                or ReturnSel["Value"][0]["ItemType"] == "判断":
            strDelItemb = """
                    UPDATE itemb T1
                    SET
                    update_user='""" + str(_request["operationUserID"]) + """',
                    update_time=DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'),
                    T1.IsDelete='1'
                    WHERE
                    T1.ItemCode='""" + str(_request["ItemCode"]) + """'
                """
            ReturnDel = dbHelp.Exec(strDelItemb)
    return _respon


def _api_test_question_tree_view(_request):
    '''
        /api/test.question.tree.view

         功能：题库--树形节点查询    负责人：陈公智
         编写：cgz
         :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""}, "MID": 2, "Num_Now":1, "Num_Every":2}
         :param _request["MID"]:MID（对应数据字典中的MID）
          :param _request["Num_Now"]:当前页
         :param _request["Num_Every"]:每页行数
         :return:_request返回信息={"pageCount": 6, "CountNum": 12, "ItemList": [{"GroupType": "", "ItemType": "", "HowHard": "", "ItemCode": 1,
                "ItemQuestion": " ", "ItemAnswer": ""}],
                 "ReturnValue": true, "currentPage": 1, "RowNum": 2, "ErrorInfo": {"ErrorCode": 0, "ErrorMsg": ""}, "IsError": false}
         :param _request["ItemList"]:每页行数
                 :param _request["GroupType"]:标签-知识点
                 :param _request["ItemType"]:试题类型
                 :param _request["HowHard"]:标签-难易度
                 :param _request["ItemCode"]:题目编码
                 :param _request["ItemQuestion"]:题目
                 :param _request["ItemAnswer"]:参考答案
         :param _request["pageCount"]:总页数
         :param _request["CountNum"]:总行数
         :param _request["RowNum"]:当前页行数
         :param _request["currentPage"]:当前页
         '''

    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}

    # strPID = ''  # 用于保存MID，进行子查询

    strCount = """
                                SELECT
                                T1.ItemCode
                                FROM
                                itema T1
                                WHERE
                                T1.JobID ='""" + str(_request["MID"]) + """'
                                AND
                                T1.IsDelete='0'
                            """

    strSqlGetAllRowNum = dbHelp.Select(strCount)
    if strSqlGetAllRowNum["RowNum"] == 0:
        _respon["ErrorInfo"]["ErrorCode"] = 1
        _respon["ErrorInfo"]["ErrorMsg"] = "无查询到任何题目！"
        _respon["IsError"] = True
        _respon["ReturnValue"] = False
        _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]
    else:

        objReturnPag = complete.FY_Paging(_request["Num_Now"], int(len(strSqlGetAllRowNum["Value"])),
                                          _request["Num_Every"])
        number_BeginGetRowNumer = objReturnPag["number_BeginGetRowNumer"]
        number_EveryPageHadNum = objReturnPag["number_EveryPageHadNum"]
        number_AllPageNumer = objReturnPag["number_AllPageNumer"]
        number_PageNumer_Now = objReturnPag["number_PageNumer_Now"]

        SelectItem = """
                                SELECT
                                T1.ItemCode,
                                T1.ItemType,
                                T1.ItemQuestion,
                                T1.ItemAnswer,
                                T1.GroupType,
                                T1.HowHard
                                FROM
                                itema T1
                                WHERE
                                T1.JobID ='""" + str(_request["MID"]) + """'
                                 AND
                                T1.IsDelete='0'
                                 limit  """ + str(number_BeginGetRowNumer) + """ , """ + str(number_EveryPageHadNum) + """
                            """

        returnObject = dbHelp.Select(SelectItem)
        if returnObject["RowNum"] != 0:
            _respon["IsError"] = returnObject["IsError"]
            _respon["ErrorInfo"]["ErrorCode"] = returnObject["ErrorCode"]
            _respon["ErrorInfo"]["ErrorMsg"] = returnObject["ErrorMsg"]
            _respon["ReturnValue"] = returnObject["ReturnValue"]
            _respon["ItemList"] = returnObject["Value"]

            _respon["pageCount"] = number_AllPageNumer
            _respon["currentPage"] = number_PageNumer_Now
            _respon["RowNum"] = returnObject["RowNum"]
            _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]


    # SqlOne = """
    #         SELECT
    #         MID
    #         FROM
    #         tb_class T1
    #         WHERE
    #         T1.PID='""" + str(_request["MID"]) + """'
    #         AND
    #         T1.IsDelete='0'
    #     """
    # returnItem = dbHelp.Select(SqlOne)
    # # 可能存在子节点
    # if len(returnItem["Value"]) != 0:
    #     strPID = str(_request["MID"]) + ","
    #     strPIDOne = ''
    #     for i in returnItem["Value"]:
    #         strPIDOne = strPIDOne + str(i["MID"]) + ","
    #
    #     strPID = strPID + strPIDOne
    #
    #     # 根据子节点，获取其子节点的MID
    #     SqlTwo = """
    #                 SELECT
    #                 MID
    #                 FROM
    #                 tb_class T1
    #                 WHERE
    #                 T1.PID IN  (""" + strPIDOne[0:len(strPIDOne) - 1] + """)
    #                 AND
    #                 T1.IsDelete='0'
    #             """
    #     returnSqlTwo = dbHelp.Select(SqlTwo)
    #
    #     if len(returnSqlTwo["Value"]) != 0:
    #         strPIDTwo = ''
    #         for i in returnSqlTwo["Value"]:
    #             strPIDTwo = strPIDTwo + str(i["MID"]) + ","
    #
    #         strPID = strPID + strPIDTwo
    #
    #         Sqlthree = """
    #                             SELECT
    #                             MID
    #                             FROM
    #                             tb_class T1
    #                             WHERE
    #                             T1.PID IN  (""" + strPIDTwo[0:len(strPIDTwo) - 1] + """)
    #                             AND
    #                             T1.IsDelete='0'
    #                         """
    #         returnSqlthree = dbHelp.Select(Sqlthree)
    #
    #         if len(returnSqlthree["Value"]) != 0:
    #             strPIDthree = ''
    #
    #             for i in returnSqlthree["Value"]:
    #                 strPIDthree = strPIDthree + str(i["MID"]) + ","
    #
    #             strPID = strPID + strPIDthree
    #         else:
    #             pass
    #     else:
    #         pass
    #     # 分页查询
    #     strCount = """
    #                         SELECT
    #                         T1.ItemCode
    #                         FROM
    #                         itema T1
    #                         WHERE
    #                         T1.JobID IN (""" + strPID[0:len(strPID) - 1] + """)
    #                         AND
    #                         T1.IsDelete='0'
    #                     """
    #     strSqlGetAllRowNum = dbHelp.Select(strCount)
    #     if strSqlGetAllRowNum["RowNum"] == 0:
    #         _respon["ErrorInfo"]["ErrorCode"] = 1
    #         _respon["ErrorInfo"]["ErrorMsg"] = "无查询到任何题目！"
    #         _respon["IsError"] = True
    #         _respon["ReturnValue"] = False
    #         _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]
    #     else:
    #
    #         objReturnPag = complete.FY_Paging(_request["Num_Now"], int(len(strSqlGetAllRowNum["Value"])),
    #                                           _request["Num_Every"])
    #         number_BeginGetRowNumer = objReturnPag["number_BeginGetRowNumer"]
    #         number_EveryPageHadNum = objReturnPag["number_EveryPageHadNum"]
    #         number_AllPageNumer = objReturnPag["number_AllPageNumer"]
    #         number_PageNumer_Now = objReturnPag["number_PageNumer_Now"]
    #
    #         SelectItem = """
    #                         SELECT
    #                         T1.ItemCode,
    #                         T1.ItemType,
    #                         T1.ItemQuestion,
    #                         T1.ItemAnswer,
    #                         T1.GroupType,
    #                         T1.HowHard
    #                         FROM
    #                         itema T1
    #                         WHERE
    #                         T1.JobID IN (""" + strPID[0:len(strPID) - 1] + """)
    #                          AND
    #                         T1.IsDelete='0'
    #                          limit  """ + str(number_BeginGetRowNumer) + """ , """ + str(number_EveryPageHadNum) + """
    #                     """
    #
    #         returnObject = dbHelp.Select(SelectItem)
    #         if returnObject["RowNum"] != 0:
    #             _respon["IsError"] = returnObject["IsError"]
    #             _respon["ErrorInfo"]["ErrorCode"] = returnObject["ErrorCode"]
    #             _respon["ErrorInfo"]["ErrorMsg"] = returnObject["ErrorMsg"]
    #             _respon["ReturnValue"] = returnObject["ReturnValue"]
    #             _respon["ItemList"] = returnObject["Value"]
    #
    #             _respon["pageCount"] = number_AllPageNumer
    #             _respon["currentPage"] = number_PageNumer_Now
    #             _respon["RowNum"] = returnObject["RowNum"]
    #             _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]
    # else:
    #     # 没有子节点
    #     strCount = """
    #         SELECT
    #             T1.ItemCode
    #             FROM
    #             itema T1
    #             WHERE
    #             T1.JobID='""" + str(_request["MID"]) + """'
    #             AND
    #             T1.IsDelete='0'
    #         """
    #     strSqlGetAllRowNum = dbHelp.Select(strCount)
    #     if strSqlGetAllRowNum["RowNum"] == 0:
    #         _respon["ErrorInfo"]["ErrorCode"] = 1
    #         _respon["ErrorInfo"]["ErrorMsg"] = "无查询到任何题目！"
    #         _respon["IsError"] = True
    #         _respon["ReturnValue"] = False
    #         _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]
    #     else:
    #
    #         objReturnPag = complete.FY_Paging(_request["Num_Now"], int(len(strSqlGetAllRowNum["Value"])),
    #                                           _request["Num_Every"])
    #         number_BeginGetRowNumer = objReturnPag["number_BeginGetRowNumer"]
    #         number_EveryPageHadNum = objReturnPag["number_EveryPageHadNum"]
    #         number_AllPageNumer = objReturnPag["number_AllPageNumer"]
    #         number_PageNumer_Now = objReturnPag["number_PageNumer_Now"]
    #         SelectItem = """
    #                 SELECT
    #                 T1.ItemCode,
    #                 T1.ItemType,
    #                 T1.ItemQuestion,
    #                 T1.ItemAnswer,
    #                 T1.GroupType,
    #                 T1.HowHard
    #                 FROM
    #                 itema T1
    #                 WHERE
    #                 T1.JobID='""" + str(_request["MID"]) + """'
    #                 AND
    #                 T1.IsDelete='0'
    #                 limit  """ + str(number_BeginGetRowNumer) + """ , """ + str(number_EveryPageHadNum) + """
    #             """
    #         returnObject = dbHelp.Select(SelectItem)
    #         if returnObject["RowNum"] != 0:
    #             _respon["IsError"] = returnObject["IsError"]
    #             _respon["ErrorInfo"]["ErrorCode"] = returnObject["ErrorCode"]
    #             _respon["ErrorInfo"]["ErrorMsg"] = returnObject["ErrorMsg"]
    #             _respon["ReturnValue"] = returnObject["ReturnValue"]
    #             _respon["ItemList"] = returnObject["Value"]
    #
    #             _respon["pageCount"] = number_AllPageNumer
    #             _respon["currentPage"] = number_PageNumer_Now
    #             _respon["RowNum"] = returnObject["RowNum"]
    #             _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]

    return _respon


def _api_test_question_all_view(_request):
    '''
            /api/test.question.all.view

             功能：题库--全局筛选查询    负责人：陈公智
             编写：cgz
             :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},"rTables": [{"ItemQuestion":"选择"},{"GroupType":"后端"}], "Num_Now":1, "Num_Every":2}
             :param _request["rTables"]:模糊查询字典
                      :param _request["ItemQuestion"]:题目
                     :param _request["GroupType"]:标签-知识点
                     //可根据GroupType，ItemQuestion模糊查询，查询全部:rTables=[]
             :param _request["Num_Now"]:当前页
             :param _request["Num_Every"]:每页行数
             :return:_request返回信息={"pageCount": 1, "CountNum": 1, "rTables": [{"GroupType": "", "ItemType": "", "HowHard": "", "ItemCode": 11,
             "ItemQuestion": "", "ItemAnswer": ""}], "ReturnValue": true, "currentPage": 1, "RowNum": 1, "ErrorInfo": {"ErrorCode": 0, "ErrorMsg": ""}, "IsError": false}
             :param _request["rTables"]:返回集合字典
                     :param _request["GroupType"]:标签-知识点
                     :param _request["ItemType"]:试题类型
                     :param _request["HowHard"]:标签-难易度
                     :param _request["ItemCode"]:题目编码
                     :param _request["ItemQuestion"]:题目
                     :param _request["ItemAnswer"]:参考答案
             :param _request["pageCount"]:总页数
             :param _request["CountNum"]:总行数
             :param _request["RowNum"]:当前页行数
             :param _request["currentPage"]:当前页
             '''
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    strSql = """
        SELECT
        T1.ItemCode,
        T1.ItemType,
        T1.ItemQuestion,
        T1.ItemAnswer,
        T1.HowHard,
        T1.GroupType
        FROM
        itema T1
        WHERE
        T1.IsDelete='0'
    """
    rTables = _request["rTables"]

    # 查询条件为空，查询全部信息
    if len(rTables) == 0:
        pass
    else:
        # 查询条件不为空
        for i in rTables:
            for a in i:
                if a == "ItemQuestion":
                    if len(i[a]) == 0:
                        pass
                    else:
                        strSql = strSql + "\nAND T1.ItemQuestion like '%" + str(i["ItemQuestion"]) + "%'"
                else:
                    pass
                if a == "HowHard":
                    if len(i[a]) == 0:
                        pass
                    else:
                        strSql = strSql + "\nAND T1.ItemType = '" + str(i["HowHard"]) + "'"
                else:
                    pass

                if a == "GroupType":
                    if len(i[a]) == 0:
                        pass
                    else:
                        strSql = strSql + "\nAND T1.GroupType ='" + str(i["GroupType"]) + "'"
                else:
                    pass

                if a == "ItemType":
                    if len(i[a]) == 0:
                        pass
                    else:
                        strSql = strSql + "\nAND T1.ItemType = '" + str(i["ItemType"]) + "'"
                else:
                    pass
    strSqlGetAllRowNum = dbHelp.Select(strSql)
    if strSqlGetAllRowNum["RowNum"] == 0:
        _respon["ErrorInfo"]["ErrorCode"] = 1
        _respon["ErrorInfo"]["ErrorMsg"] = "无查询到任何试题！"
        _respon["IsError"] = True
        _respon["ReturnValue"] = False
        _respon["CountNum"] = strSqlGetAllRowNum["RowNum"]
    else:

        objReturnPag = complete.FY_Paging(_request["Num_Now"], int(len(strSqlGetAllRowNum["Value"])),
                                          _request["Num_Every"])
        number_BeginGetRowNumer = objReturnPag["number_BeginGetRowNumer"]
        number_EveryPageHadNum = objReturnPag["number_EveryPageHadNum"]
        number_AllPageNumer = objReturnPag["number_AllPageNumer"]
        number_PageNumer_Now = objReturnPag["number_PageNumer_Now"]

        strsql = strSql + "limit " + str(number_BeginGetRowNumer) + ", " + str(number_EveryPageHadNum) + ""

        selectObj = dbHelp.Select(strsql)
        _respon["IsError"] = selectObj["IsError"]
        _respon["ErrorInfo"]["ErrorCode"] = selectObj["ErrorCode"]
        _respon["ErrorInfo"]["ErrorMsg"] = selectObj["ErrorMsg"]
        _respon["ReturnValue"] = selectObj["ReturnValue"]
        if selectObj["ReturnValue"]:
            _respon["pageCount"] = number_AllPageNumer
            _respon["currentPage"] = number_PageNumer_Now
            _respon["RowNum"] = selectObj["RowNum"]
            _respon["CountNum"] = len(strSqlGetAllRowNum["Value"])
            _respon["rTables"] = selectObj["Value"]
        else:
            pass
    return _respon


def _api_test_question_edit_v2(_request):
    """
    /api/test.question.edit.v2 接口 题目编辑第二版

    编写：宋德聪
    时间：2016年12月10日 09:53:55
    备注：根据临时讨论结果做出来的测试接口

    :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},
        "operationUserID":"","ItemCode":"","ItemQuestion":"","ItemAnswer":"","HowHard":"","GroupType":"","ItemQuestion_Old":"","ItemAnswer_Old":"","HowHard_Old":"","GroupType_Old":"",
        "list_input":[{"AnswerCode":"","OrderCode":"","AnswerText":"","OrderCode_Old":"","AnswerText_Old":""}]
        }

    :param _request["operationUserID"] 操作账号
    :param _request["ItemCode"] 试题编码

    :param _request["ItemQuestion"] 题目
    :param _request["ItemAnswer"] 参考答案
    :param _request["HowHard"] 标签-难易度
    :param _request["GroupType"] 标签-知识点

    :param _request["ItemAnswer_Old"] 参考答案_校对用
    :param _request["ItemQuestion_Old"] 问题_校对用
    :param _request["HowHard_Old"] 答案_校对用
    :param _request["GroupType_Old"] 知识点_校对用


    :param _request["list_input"] 需要执行编辑的记录
    :param _request["list_input"][i]["AnswerCode"] 答案编码
    :param _request["list_input"][i]["OrderCode"] 答案序号
    :param _request["list_input"][i]["AnswerText"] 答案内容
    :param _request["list_input"][i]["OrderCode_Old"] 答案序号校对用
    :param _request["list_input"][i]["AnswerText_Old"] 答案内容校对用

    :return: _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}


    """

    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon1 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon2 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon3 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}

    # print _request

    # 01 主表部分处理--执行主表更新
    # 判断主表记录是否有需要修改的
    # _request["ItemQuestion"] _request["ItemAnswer"] _request["HowHard"] _request["GroupType"] _request["ItemQuestion_Old"]  _request["ItemAnswer_Old"]  _request["HowHard_Old"] _request["GroupType_Old"]
    cs_int_difference_main = 0
    if _request["ItemQuestion"] != _request["ItemQuestion_Old"]:
        cs_int_difference_main = cs_int_difference_main + 1
    else:
        pass
    if _request["ItemAnswer"] != _request["ItemAnswer_Old"]:
        cs_int_difference_main = cs_int_difference_main + 1
    else:
        pass
    if _request["HowHard"] != _request["HowHard_Old"]:
        cs_int_difference_main = cs_int_difference_main + 1
    else:
        pass
    if _request["GroupType"] != _request["GroupType_Old"]:
        cs_int_difference_main = cs_int_difference_main + 1
    else:
        pass

    if cs_int_difference_main ==0:
        # 新旧值一致，不需要执行编辑操作
        _respon1["IsError"] = False
        _respon1["ErrorInfo"]["ErrorCode"] = "0"
        _respon1["ErrorInfo"]["ErrorMsg"] = "主表数据没发生变化，不执行修改"
        _respon1["ReturnValue"] = True
    else:
        # 新旧值一致，需要执行编辑操作
        value_update_main = {}
        value_update_main["tbaleName"] = "itema"

        value_update_main["set_normal"] = {}
        value_update_main["set_normal"].update({"update_user": _request["operationUserID"]})  # 更新人
        value_update_main["set_normal"].update({"ItemQuestion": _request["ItemQuestion"]})  # 问题
        value_update_main["set_normal"].update({"ItemAnswer": _request["ItemAnswer"]})  # 答案
        value_update_main["set_normal"].update({"HowHard": _request["HowHard"]})  # 难度
        value_update_main["set_normal"].update({"GroupType": _request["GroupType"]})  # 知识点

        value_update_main["set_special"] = {}
        value_update_main["set_special"].update({"update_time": "now()"})  # 更新时间

        value_update_main["where_normal"] = {}
        value_update_main["where_normal"].update({"ItemCode": _request["ItemCode"]})  # 判断标准
        value_update_main["where_normal"].update({"ItemQuestion": _request["ItemQuestion_Old"]})  # 问题_校对用
        value_update_main["where_normal"].update({"ItemAnswer": _request["ItemAnswer_Old"]})  # 答案_校对用
        value_update_main["where_normal"].update({"HowHard": _request["HowHard_Old"]})  # 难度_校对用
        value_update_main["where_normal"].update({"GroupType": _request["GroupType_Old"]})  # 知识点_校对用

        value_update_main["where_special"] = {}

        sql_01_update_main = dbHelp.ff_sql_gotten_update(value_update_main)
        obj_01 = dbHelp.Exec(sql_01_update_main)
        _respon1["IsError"] = obj_01["IsError"]
        _respon1["ErrorInfo"]["ErrorCode"] = obj_01["ErrorCode"]
        _respon1["ErrorInfo"]["ErrorMsg"] = obj_01["ErrorMsg"]
        _respon1["ReturnValue"] = obj_01["ReturnValue"]


    # 02 从表部分处理
    # 021 从表新增编辑处理
    # 遍历传入参数列表，AnswerCode为0的表示要执行新增
    # 遍历传入参数列表，判断OrderCode|OrderCode_Old|AnswerText|AnswerText_Old，有不同则执行编辑
    # "list_input":[{"AnswerCode":"","OrderCode":"1","AnswerText":"a","OrderCode_Old":"","AnswerText_Old":""},{"AnswerCode":"22","OrderCode":"2","AnswerText":"b","OrderCode_Old":"","AnswerText_Old":""}]
    cs_int_num_do=0
    cs_int_num_add=0
    cs_int_num_edit = 0

    # 022 从表删除处理
    # 根据主表ID，找到全部从表ID
    sql_03_select = """
            SELECT
            T1.AnswerCode
            FROM
            itemb T1
            WHERE
            T1.IsDelete = 0
            AND
            T1.ItemCode = '""" + _request["ItemCode"] + """'
        """
    obj_03 = dbHelp.Select(sql_03_select)
    if obj_03["RowNum"] == 0:
        # 没答案，不用做删除判断
        pass
    else:
        # print 'obj_03["Value"] = ',obj_03["Value"]
        # print '_request["list_input"] = ',_request["list_input"]

        # 找到的ID和传入的ID做比较，多的执行删除
        sql_04_delete_all = ""
        list_is_have = obj_03["Value"]
        for cs_one_answerCode_InDB in list_is_have:
            cs_code_InDB = cs_one_answerCode_InDB["AnswerCode"]
            cs_tf_need_Delete = True  # 是否需要删除
            for cs_one_answer_dic2 in _request["list_input"]:
                if cs_one_answer_dic2["AnswerCode"] == "undefined":
                    # 新增记录，不做判断
                    pass
                else:
                    # 非新增记录，做判断
                    cs_code_InInput = cs_one_answer_dic2["AnswerCode"]
                    if int(cs_code_InDB) == int(cs_code_InInput):
                        # 数据库有，传入有，不需要删除，修改状态标识
                        cs_tf_need_Delete = False
                        # print cs_tf_need_Delete
                        # print ' == ',cs_tf_need_Delete,'123'
                    else:
                        pass
                        # 数据库有，传入没有 ,可能需要删除，不变更默认值：需要删除
                    #     print '!=',cs_code_InDB,cs_code_InInput,type(cs_code_InDB),type(cs_code_InInput)
                    # print 'cs_code_InInput = ', cs_code_InInput, 'cs_code_InDB = ', cs_code_InDB,cs_tf_need_Delete
            # 循环判断结束，如果没有一个是匹配的，证明要删除，cs_tf_need_Delete = 默认值True
            if cs_tf_need_Delete == False:
                _respon3["IsError"] = False
                _respon3["ErrorInfo"]["ErrorCode"] = ""
                _respon3["ErrorInfo"]["ErrorMsg"] = ""
                _respon3["ReturnValue"] = True
            else:
                # 拼接删除子语句
                value_delete = {}
                value_delete["tbaleName"] = "itemb"

                value_delete["set_normal"] = {}
                value_delete["set_normal"].update({"update_user": _request["operationUserID"]})
                value_delete["set_normal"].update({"IsDelete": 1})

                value_delete["set_special"] = {}
                value_delete["set_special"].update({"update_time": "now()"})

                value_delete["where_normal"] = {}
                value_delete["where_normal"].update({"AnswerCode": cs_code_InDB})

                value_delete["where_special"] = {}

                sql_04_delete_one = dbHelp.ff_sql_gotten_update(value_delete)

                sql_04_delete_all = sql_04_delete_all + sql_04_delete_one + " ; "

            # print sql_04_delete_all

        # 全部结果分析完成，执行删除
        obj_04 = dbHelp.Exec(sql_04_delete_all)
        _respon3["IsError"] = obj_04["IsError"]
        _respon3["ErrorInfo"]["ErrorCode"] = obj_04["ErrorCode"]
        _respon3["ErrorInfo"]["ErrorMsg"] = obj_04["ErrorMsg"]
        _respon3["ReturnValue"] = obj_04["ReturnValue"]


    sql_02_do_all = ""
    for cs_one_answer_dic in _request["list_input"]:
        cs_int_num_do = cs_int_num_do + 1
        if cs_one_answer_dic["AnswerCode"]=="undefined":
            #执行新增 这里是2016年12月12日 17:35:31执行过修改
            cs_int_num_add = cs_int_num_add + 1

            cs_one_newID_01 = str((dbHelp.GetNewids("itemb"))["Value"])
            value_insert = {}
            value_insert["tbaleName"] = "itemb"
            value_insert["value_normal"] = {}
            value_insert["value_normal"].update({"create_user": _request["operationUserID"]})
            value_insert["value_normal"].update({"AnswerCode": cs_one_newID_01})
            value_insert["value_normal"].update({"ItemCode": _request["ItemCode"]})
            value_insert["value_normal"].update({"OrderCode": cs_one_answer_dic["OrderCode"]})
            value_insert["value_normal"].update({"AnswerText": cs_one_answer_dic["AnswerText"]})
            value_insert["value_normal"].update({"IsDelete": 0})

            value_insert["value_special"] = {}
            value_insert["value_special"].update({"create_time": "now()"})

            # 获得单条拼接语句
            sql_02_insert_one = dbHelp.ff_sql_gotten_insert(value_insert)
            # 登记到总执行语句中
            sql_02_do_all = sql_02_do_all + sql_02_insert_one + " ; "

        else:
            # 执行编辑
            # 根据old判断是否需要执行编辑
            cs_int_difference_ex = 0
            if cs_one_answer_dic["OrderCode"]!=cs_one_answer_dic["OrderCode_Old"]:
                cs_int_difference_ex = cs_int_difference_ex + 1
            else:
                pass
            if cs_one_answer_dic["AnswerText"]!= cs_one_answer_dic["AnswerText_Old"]:
                cs_int_difference_ex = cs_int_difference_ex + 1
            else:
                pass
            if cs_int_difference_ex == 0:
                # 不执行更新操作,不用拼接SQL语句
                pass
            else:
                # 执行更新操作
                cs_int_num_edit = cs_int_num_edit + 1

                value_update = {}
                value_update["tbaleName"] = "itemb"

                value_update["set_normal"] = {}
                value_update["set_normal"].update({"update_user": _request["operationUserID"]})
                value_update["set_normal"].update({"AnswerCode":cs_one_answer_dic["AnswerCode"]})
                value_update["set_normal"].update({"AnswerText":cs_one_answer_dic["AnswerText"]})

                value_update["set_special"] = {}
                value_update["set_special"].update({"update_time": "now()"})

                value_update["where_normal"] = {}
                value_update["where_normal"].update({"AnswerCode": cs_one_answer_dic["AnswerCode"]})
                value_update["where_normal"].update({"OrderCode": cs_one_answer_dic["OrderCode_Old"]})
                value_update["where_normal"].update({"AnswerText": cs_one_answer_dic["AnswerText_Old"]})

                value_update["where_special"] = {}

                # 拼接执行子语句
                sql_02_update_one = dbHelp.ff_sql_gotten_update(value_update)
                # 登记到总SQL语句中
                sql_02_do_all = sql_02_do_all + sql_02_update_one + " ; "

    # 结束的第一期的FOR判断，执行INSERT和UPDATE的混合操作
    obj_02 = dbHelp.Exec(sql_02_do_all)
    _respon2["IsError"] = obj_02["IsError"]
    _respon2["ErrorInfo"]["ErrorCode"] = obj_02["ErrorCode"]
    _respon2["ErrorInfo"]["ErrorMsg"] = obj_02["ErrorMsg"]
    _respon2["ReturnValue"] = obj_02["ReturnValue"]



    _respon["IsError"] = _respon1["IsError"] and _respon2["IsError"] and _respon3["IsError"]
    _respon["ErrorInfo"]["ErrorCode"] = \
        str(_respon1["ErrorInfo"]["ErrorCode"]) + \
        str(_respon2["ErrorInfo"]["ErrorCode"] )+ \
        str(_respon3["ErrorInfo"]["ErrorCode"])

    _respon["ErrorInfo"]["ErrorMsg"] = \
        _respon1["ErrorInfo"]["ErrorMsg"] + \
        _respon2["ErrorInfo"]["ErrorMsg"] + \
        _respon3["ErrorInfo"]["ErrorMsg"]

    _respon["ReturnValue"] = \
        _respon1["ReturnValue"] and \
        _respon2["ReturnValue"] and \
        _respon3["ReturnValue"]


    return _respon


def _api_test_question_edit(_request):
    """
    /api/test.question.edit 接口 题目编辑

    编写：sdc
    :param _request:传入参数 ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},
        "operationUserID":"","ItemCode":"","ItemQuestion":"","ItemAnswer":"","HowHard":"","GroupType":"","ItemQuestion_Old":"","ItemAnswer_Old":"","HowHard_Old":"","GroupType_Old":"",
        "list_add":[{"OrderCode":"","AnswerText":""}],
        "list_edit":[{"AnswerCode":"","OrderCode":"","AnswerText":"","OrderCode_Old":"","AnswerText_Old":""}],
        "list_delete":[{"AnswerCode":""}]

    :param _request["operationUserID"] 操作账号
    :param _request["ItemCode"] 试题编码

    :param _request["ItemQuestion"] 题目
    :param _request["ItemAnswer"] 参考答案
    :param _request["HowHard"] 标签-难易度
    :param _request["GroupType"] 标签-知识点

    :param _request["ItemAnswer_Old"] 参考答案_校对用
    :param _request["ItemQuestion_Old"] 问题_校对用
    :param _request["HowHard_Old"] 答案_校对用
    :param _request["GroupType_Old"] 知识点_校对用

    :param _request["list_add"] 需要执行新增的记录
    :param _request["list_add"][i]["OrderCode"] 答案序号
    :param _request["list_add"][i]["AnswerText"] 答案内容


    :param _request["list_edit"] 需要执行编辑的记录
    :param _request["list_edit"][i]["AnswerCode"] 答案编码
    :param _request["list_edit"][i]["OrderCode"] 答案序号
    :param _request["list_edit"][i]["AnswerText"] 答案内容
    :param _request["list_edit"][i]["OrderCode_Old"] 答案序号校对用
    :param _request["list_edit"][i]["AnswerText_Old"] 答案内容校对用


    :param _request["list_delete"] 需要执行删除的记录
    :param _request["list_delete"][i]["AnswerCode"] 答案编码




    :return: _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    """

    # _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon1 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon2 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon3 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}
    _respon4 = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": True, "IsError": False}

    # part 1 更新主表信息

    value_update_main = {}
    value_update_main["tbaleName"] = "itema"

    value_update_main["set_normal"] = {}
    value_update_main["set_normal"].update({"update_user": _request["operationUserID"]})  # 更新人
    value_update_main["set_normal"].update({"ItemQuestion": _request["ItemQuestion"]})  # 问题
    value_update_main["set_normal"].update({"ItemAnswer": _request["ItemAnswer"]})  # 答案
    value_update_main["set_normal"].update({"HowHard": _request["HowHard"]})  # 难度
    value_update_main["set_normal"].update({"GroupType": _request["GroupType"]})  # 知识点

    value_update_main["set_special"] = {}
    value_update_main["set_special"].update({"update_time": "now()"})  # 更新时间

    value_update_main["where_normal"] = {}
    value_update_main["where_normal"].update({"ItemCode": _request["ItemCode"]})  # 判断标准
    value_update_main["where_normal"].update({"ItemQuestion": _request["ItemQuestion_Old"]})  # 问题_校对用
    value_update_main["where_normal"].update({"ItemAnswer": _request["ItemAnswer_Old"]})  # 答案_校对用
    value_update_main["where_normal"].update({"HowHard": _request["HowHard_Old"]})  # 难度_校对用
    value_update_main["where_normal"].update({"GroupType": _request["GroupType_Old"]})  # 知识点_校对用

    value_update_main["where_special"] = {}

    sql_01_update_main = dbHelp.ff_sql_gotten_update(value_update_main)
    obj_01 = dbHelp.Exec(sql_01_update_main)
    _respon1["IsError"] = obj_01["IsError"]
    _respon1["ErrorInfo"]["ErrorCode"] = obj_01["ErrorCode"]
    _respon1["ErrorInfo"]["ErrorMsg"] = obj_01["ErrorMsg"]
    _respon1["ReturnValue"] = obj_01["ReturnValue"]

    # part 2 更新从表信息

    # part 21 新增从表信息

    # 从表新增部分开始↓ "list_add":[{"OrderCode":"","AnswerText":""}],
    if len(_request["list_add"]) == 0:
        # 没有需要新增的从表信息
        pass
    else:
        # 获取新增的数量
        num_insertNum = len(_request["list_add"])
        # 获取新增的ID列表
        objReturn_NewIDs = dbHelp.GetSomeIDs("itemb", num_insertNum)
        # 设置主SQL执行语句
        sql_02_insert_all = ""
        # 执行拼接子执行语句
        for i in range(0, num_insertNum):
            value_insert = {}
            value_insert["tbaleName"] = "itemb"
            value_insert["value_normal"] = {}
            value_insert["value_normal"].update({"create_user": _request["operationUserID"]})
            value_insert["value_normal"].update({"AnswerCode": str(objReturn_NewIDs["numberList"][i])})
            value_insert["value_normal"].update({"ItemCode": _request["ItemCode"]})
            value_insert["value_normal"].update({"OrderCode": _request["list_add"][i]["OrderCode"]})
            value_insert["value_normal"].update({"AnswerText": _request["list_add"][i]["AnswerText"]})

            value_insert["value_special"] = {}
            value_insert["value_special"].update({"create_time": "now()"})

            # 获得单条拼接语句
            sql_02_insert_one = dbHelp.ff_sql_gotten_insert(value_insert)
            # 拼接总执行语句
            sql_02_insert_all = sql_02_insert_all + sql_02_insert_one + " ; "

        obj_02 = dbHelp.Exec(sql_02_insert_all)
        _respon2["IsError"] = obj_02["IsError"]
        _respon2["ErrorInfo"]["ErrorCode"] = obj_02["ErrorCode"]
        _respon2["ErrorInfo"]["ErrorMsg"] = obj_02["ErrorMsg"]
        _respon2["ReturnValue"] = obj_02["ReturnValue"]
    # 从表新增部分操作完成↑

    # part 22 编辑从表信息

    # 从表编辑部分开始 "list_edit":[{"AnswerCode":"","OrderCode":"","AnswerText":"","OrderCode_Old":"","AnswerText_Old":""}],
    if len(_request["list_edit"]) == 0:
        pass
    else:
        # 设置执行总语句
        sql_03_update_all = ""

        for i in range(0, len(_request["list_edit"])):
            value_update = {}
            value_update["tbaleName"] = "itemb"

            value_update["set_normal"] = {}
            value_update["set_normal"].update({"update_user": _request["operationUserID"]})
            value_update["set_normal"].update({"AnswerCode": _request["list_edit"][i]["AnswerCode"]})
            value_update["set_normal"].update({"AnswerText": _request["list_edit"][i]["AnswerText"]})

            value_update["set_special"] = {}
            value_update["set_special"].update({"update_time": "now()"})

            value_update["where_normal"] = {}
            value_update["where_normal"].update({"AnswerCode": _request["list_edit"][i]["AnswerCode"]})
            value_update["where_normal"].update({"OrderCode": _request["list_edit"][i]["OrderCode_Old"]})
            value_update["where_normal"].update({"AnswerText": _request["list_edit"][i]["AnswerText_Old"]})

            value_update["where_special"] = {}

            # 拼接执行子语句
            sql_03_update_one = dbHelp.ff_sql_gotten_update(value_update)
            # 拼接执行总语句
            sql_03_update_all = sql_03_update_all + sql_03_update_one
        # 执行更新操作
        obj_03 = dbHelp.Exec(sql_03_update_all)
        _respon3["IsError"] = obj_03["IsError"]
        _respon3["ErrorInfo"]["ErrorCode"] = obj_03["ErrorCode"]
        _respon3["ErrorInfo"]["ErrorMsg"] = obj_03["ErrorMsg"]
        _respon3["ReturnValue"] = obj_03["ReturnValue"]

    # 从表编辑部分结束


    # part 23 删除从表信息

    # 从表删除部分开始  "list_delete":[{"AnswerCode":"","OrderCode_Old":"","AnswerText_Old":""}]
    if len(_request["list_delete"]) == 0:
        pass
    else:
        sql_04_delete_all = ""

        for i in range(0, len(_request["list_delete"])):
            value_delete = {}
            value_delete["tbaleName"] = "itemb"

            value_delete["set_normal"] = {}
            value_delete["set_normal"].update({"update_user": _request["operationUserID"]})
            value_delete["set_normal"].update({"IsDelete": 1})

            value_delete["set_special"] = {}
            value_delete["set_special"].update({"update_time": "now()"})

            value_delete["where_normal"] = {}
            value_delete["where_normal"].update({"AnswerCode": _request["list_delete"][i]["AnswerCode"]})
            # value_delete["where_normal"].update({"OrderCode": _request["list_delete"][i]["OrderCode_Old"]})
            # value_delete["where_normal"].update({"AnswerText": _request["list_delete"][i]["AnswerText_Old"]})

            value_delete["where_special"] = {}

            sql_04_delete_one = dbHelp.ff_sql_gotten_update(value_delete)

            sql_04_delete_all = sql_04_delete_all + sql_04_delete_one

        obj_04 = dbHelp.Exec(sql_04_delete_all)
        _respon4["IsError"] = obj_04["IsError"]
        _respon4["ErrorInfo"]["ErrorCode"] = obj_04["ErrorCode"]
        _respon4["ErrorInfo"]["ErrorMsg"] = obj_04["ErrorMsg"]
        _respon4["ReturnValue"] = obj_04["ReturnValue"]

    # 从表删除部分结束

    _respon["IsError"] = _respon1["IsError"] and _respon2["IsError"] and _respon3["IsError"] and _respon4["IsError"]
    _respon["ErrorInfo"]["ErrorCode"] = \
        _respon1["ErrorInfo"]["ErrorCode"] + \
        _respon2["ErrorInfo"]["ErrorCode"] + \
        _respon3["ErrorInfo"]["ErrorCode"] + \
        _respon4["ErrorInfo"]["ErrorCode"]
    _respon["ErrorInfo"]["ErrorMsg"] = \
        _respon1["ErrorInfo"]["ErrorMsg"] +\
        _respon2["ErrorInfo"]["ErrorMsg"] + \
        _respon3["ErrorInfo"]["ErrorMsg"] + \
        _respon4["ErrorInfo"]["ErrorMsg"]
    _respon["ReturnValue"] = \
        _respon1["ReturnValue"] and \
        _respon2["ReturnValue"] and \
        _respon3["ReturnValue"] and \
        _respon4["ReturnValue"]

    return _respon
